package com.neelsys.visualisation.service;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.template.Neo4jOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neelsys.visualisation.domain.CourseDesignator;
import com.neelsys.visualisation.domain.CourseLevelEnum;
import com.neelsys.visualisation.domain.CourseStreamEnum;
import com.neelsys.visualisation.domain.EntranceTest;
import com.neelsys.visualisation.domain.MajorCombination;
import com.neelsys.visualisation.domain.ui.JSONGraph;
import com.neelsys.visualisation.repository.CourseDesignatorRepository;
import com.neelsys.visualisation.repository.majorComb.MajorCombinationRepository;
import com.neelsys.visualisation.service.adapter.MajorCombAdapter;
import com.neelsys.visualisation.service.persist.PersistNodesFromExcel;


/**
 * @author mh
 * @since 04.03.11
 */
@Service
public class VisualisationService {

	private final static Logger log = LoggerFactory
			.getLogger(VisualisationService.class);

	@Autowired
	MajorCombinationRepository majorCombRepo;

	@Autowired
	Neo4jOperations template;
	
	@Autowired
	CourseDesignatorRepository cdRepo;
	
	@Autowired
	PersistNodesFromExcel dataPersist;
	
	@Transactional
	public JSONGraph persistCourseDesig() {
		
		//dataPersist.persist();
		
		majorCombRepo.sampleCypherDsl("MTECH");
		
		return new JSONGraph();

	}


	public JSONGraph getCollege() {
		System.out.println("Get College Called.");
		
		CourseDesignator courseDesig=new CourseDesignator();
		courseDesig.setCourseLevel(CourseLevelEnum.INTERMEDIATE);
		courseDesig.setCourseStream(CourseStreamEnum.ENGINEERING);
		
		MajorCombination retrievedComb = majorCombRepo.findByCourseIdentifierAndMajorIdentifier("PUC", "MPC");

		MajorCombAdapter adapter=new MajorCombAdapter(template, retrievedComb);
		
		JSONGraph jsonGraph=adapter.adaptToJsonGraph();
		
		return jsonGraph;
	}
	
	
	public JSONGraph clean() {

		System.out.println("Clean Called.");
		Neo4jDatabaseCleaner clean=new Neo4jDatabaseCleaner(template);
		clean.cleanDb();

		return new JSONGraph();

	}

}
